package it.mozzicato.apkwizard.model;

import java.io.*;

import javax.xml.parsers.*;

import org.w3c.dom.*;

/**
 * @author Roberto Mozzicato
 *
 */
public abstract class XmlResParser {

	public void parseFile(File xmlFile) {
		try {
			DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
			if(xmlFile.exists()) {
				Document doc = db.parse(xmlFile);
				Node root = doc.getFirstChild();
				Node child = root.getFirstChild();
				while (child != null) {
					if (child instanceof Element) {
						if(!parseElement((Element) child, xmlFile))
							break;
					}
					child = child.getNextSibling();
				}
			}
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	
	}

	protected abstract boolean parseElement(Element element, File parsedFile);
}
